﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace GeoFly
{
    public partial class InputParaDialog : Form
    {
        public InputParaDialog()
        {
            InitializeComponent();
        }

        private void textBox24_TextChanged(object sender, EventArgs e)
        {

        }

        private void OKButton_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("这些设置会更新以前的设置，要继续吗？", "", MessageBoxButtons.OKCancel) == DialogResult.OK)
            {
                HydroSimulate.g_ModelInputPara.GSKv = Convert.ToDouble(this.textBox1_SurfKv.Text);
                HydroSimulate.g_ModelInputPara.GLKv = Convert.ToDouble(this.textBox_LatKv.Text);
                HydroSimulate.g_ModelInputPara.GBKv = Convert.ToDouble(this.textBox_BaseKv.Text);

                HydroSimulate.g_ModelInputPara.LowWaterSurfQLoss = Convert.ToDouble(this.textBox_LowSurfLoss.Text);
                HydroSimulate.g_ModelInputPara.MidWaterSurfQLoss = Convert.ToDouble(this.textBox_CommonSurfLoss.Text);
                HydroSimulate.g_ModelInputPara.HighWaterSurfQLoss = Convert.ToDouble(this.textBox_RichSurfLoss.Text);

                HydroSimulate.g_ModelInputPara.LatQLoss = Convert.ToDouble(this.textBox_LatQLoss.Text);
                HydroSimulate.g_ModelInputPara.BaseQLoss = Convert.ToDouble(this.textBox_BaseQLoss.Text);

                HydroSimulate.g_ModelInputPara.RiverProType = (RiverType)this.comboBox_RiverProfileType.SelectedIndex;
                HydroSimulate.g_ModelInputPara.HillProType = (RiverType)this.comboBox_HillProfileType.SelectedIndex;
                HydroSimulate.g_ModelInputPara.RiverProWidth = Convert.ToDouble(this.textBox_RiverProfileWidth.Text);
                HydroSimulate.g_ModelInputPara.HillProWidth = Convert.ToDouble(this.textBox_HillProfileWidth.Text);

                HydroSimulate.g_ModelInputPara.SMCTimeWeight = Convert.ToDouble(this.textBox_SurfMuskTimeWeight.Text);
                HydroSimulate.g_ModelInputPara.SMCGridRTravelTime = Convert.ToDouble(this.textBox1_SurfMuskTravelTime.Text);
                HydroSimulate.g_ModelInputPara.LMCTimeWeight = Convert.ToDouble(this.textBox_LatMuskTimeWeight1.Text);
                HydroSimulate.g_ModelInputPara.LMCGridRTravelTime = Convert.ToDouble(this.textBox_LatMuskTravelTime.Text);
                HydroSimulate.g_ModelInputPara.BMCTimeWeight = Convert.ToDouble(this.textBox_BaseMuskTimeWeight.Text);
                HydroSimulate.g_ModelInputPara.BMCGridRTravelTime = Convert.ToDouble(this.textBox_BaseMuskTravelTime.Text);

                HydroSimulate.g_ModelInputPara.SurfQLinearFactor = Convert.ToDouble(this.textBox_SurfLinearAdjust.Text);
                HydroSimulate.g_ModelInputPara.SurfQOutFactor = Convert.ToDouble(this.textBox_SurfQOut.Text);
                HydroSimulate.g_ModelInputPara.LatQOutFactor = Convert.ToDouble(this.textBox_LatQOut.Text);
                HydroSimulate.g_ModelInputPara.DailyMeanPcpTime = Convert.ToDouble(this.textBox_DailyPcpTime.Text);
                HydroSimulate.g_ModelInputPara.SnowTemperature = Convert.ToDouble(this.textBox_SnowTemp.Text);
                HydroSimulate.g_ModelInputPara.DDF = Convert.ToDouble(this.textBox_DegreeDayCoeff.Text);
                HydroSimulate.g_ModelInputPara.DeepBaseQ = Convert.ToDouble(this.textBox_DeepBaseQ.Text);
                
                HydroSimulate.g_ModelInputPara.WritePara(HydroSimulate.path + "\\SysPara\\InputPara.txt");
            }
        }

        private void InputParaDialog_Load(object sender, EventArgs e)
        {

            this.textBox1_SurfKv.Text=HydroSimulate.g_ModelInputPara.GSKv.ToString();
            this.textBox_LatKv.Text = HydroSimulate.g_ModelInputPara.GLKv.ToString();
            this.textBox_BaseKv.Text = HydroSimulate.g_ModelInputPara.GBKv.ToString();

            this.textBox_LowSurfLoss.Text = HydroSimulate.g_ModelInputPara.LowWaterSurfQLoss.ToString();
            this.textBox_CommonSurfLoss.Text = HydroSimulate.g_ModelInputPara.MidWaterSurfQLoss.ToString();
            this.textBox_RichSurfLoss.Text=HydroSimulate.g_ModelInputPara.HighWaterSurfQLoss.ToString();

            this.textBox_LatQLoss.Text = HydroSimulate.g_ModelInputPara.LatQLoss.ToString();
            this.textBox_BaseQLoss.Text = HydroSimulate.g_ModelInputPara.BaseQLoss.ToString();

            this.comboBox_RiverProfileType.SelectedIndex=(int)HydroSimulate.g_ModelInputPara.RiverProType;
            this.comboBox_HillProfileType.SelectedIndex=(int)HydroSimulate.g_ModelInputPara.HillProType;
            this.textBox_RiverProfileWidth.Text = HydroSimulate.g_ModelInputPara.RiverProWidth.ToString();
            this.textBox_HillProfileWidth.Text = HydroSimulate.g_ModelInputPara.HillProWidth.ToString();

            this.textBox_SurfMuskTimeWeight.Text = HydroSimulate.g_ModelInputPara.SMCTimeWeight.ToString();
            this.textBox1_SurfMuskTravelTime.Text = HydroSimulate.g_ModelInputPara.SMCGridRTravelTime.ToString();
            this.textBox_LatMuskTimeWeight1.Text = HydroSimulate.g_ModelInputPara.LMCTimeWeight.ToString();
            this.textBox_LatMuskTravelTime.Text = HydroSimulate.g_ModelInputPara.LMCGridRTravelTime.ToString();
            this.textBox_BaseMuskTimeWeight.Text = HydroSimulate.g_ModelInputPara.BMCTimeWeight.ToString();
            this.textBox_BaseMuskTravelTime.Text=HydroSimulate.g_ModelInputPara.BMCGridRTravelTime.ToString();

            this.textBox_SurfLinearAdjust.Text = HydroSimulate.g_ModelInputPara.SurfQLinearFactor.ToString();
            this.textBox_SurfQOut.Text = HydroSimulate.g_ModelInputPara.SurfQOutFactor.ToString();
            this.textBox_LatQOut.Text = HydroSimulate.g_ModelInputPara.LatQOutFactor.ToString();
            this.textBox_DailyPcpTime.Text=HydroSimulate.g_ModelInputPara.DailyMeanPcpTime.ToString();
            this.textBox_SnowTemp.Text=HydroSimulate.g_ModelInputPara.SnowTemperature.ToString();
            this.textBox_DegreeDayCoeff.Text = HydroSimulate.g_ModelInputPara.DDF.ToString();
            this.textBox_DeepBaseQ.Text = HydroSimulate.g_ModelInputPara.DeepBaseQ.ToString();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            double X =Convert.ToDouble( this.textBox_SurfMuskTimeWeight.Text);
            double K = Convert.ToDouble(this.textBox1_SurfMuskTravelTime.Text)/60.0;
            double m_deltaT = 1.0;
            double denominator = K * (1 - X) + 0.5 * m_deltaT;
            double  C1 = (X * K + 0.5 * m_deltaT) / denominator;
            double C2 = (0.5 * m_deltaT - X * K) / denominator;
            double C3 = (K * (1 - X) - 0.5 * m_deltaT) / denominator;
            MessageBox.Show("C1="+C1.ToString("0.0000")+" C2="+C2.ToString("0.0000")+" C3="+C3.ToString("0.0000"));
        }
    }
}
